<template>
  <section class="c-header-box" :class="[{'error':isError},{'on':!isScroll}]">
    <section class="main g-width-box g-cen-y">
      <div class="logo g-back" />
      <nav class="nav-btn-box g-dis">
        <router-link
          v-for="(m,i) in navArr"
          :key="i"
          class="btn"
          :to="m.path"
          :class="[isPath ==m.path && 'on']"
        >
          {{ m.name }}
        </router-link>
      </nav>
      <div class="btn-box g-cen-y">
        <a class="btn g-cen-cen" href="https://csm.emao.com/login" target="_blank">去登录</a>
      </div>
    </section>
  </section>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
  data () {
    return {
      isPath: this.$route.path || '/',
      navArr: [
        { path: '/', name: '首页' },
        { path: '/page2', name: '订单' },
        { path: '/page3', name: '资讯' },
        { path: '/page4', name: '联系我们' }
      ]
    }
  },
  computed: {
    ...mapGetters('header', ['isScroll', 'isError'])
  },
  watch: {
    $route (e) {
      this.isPath = this.$route.path || '/'
    }
  }
}
</script>
<style lang="scss" scoped>
.c-header-box{
  top: 0;
  width: 100%;
  z-index: 999;
  height: 90px;
  position: absolute;
  left: 0;
  min-width: 1200px;
  background-color: transparent;
  &.on{
    position: fixed;
    box-shadow: 0px 5px 15px 0px rgba(0,0,0,0.10);
    background-color: #fff;
    &:not(.error){
      animation:  headerShow .4s forwards;
    }

    .logo{
      background-image: url('/v1/img/logo-1.png');
    }
    .nav-btn-box{
      .btn{
        color: #333;
        &.on{
          color: #3C95FF;
          &::before{
            background: #3c95ff;
          }
        }
      }
    }
    .btn-box{
      .btn{
        background-color: #469AFF;
        color: #fff;
        .icon{
          // background-image: url('/v1/img/icon-1.png');
        }
      }
    }
  }
  &>.main{
    height: 100%;
  }
  .logo{
    width: 120px;
    height: 50px;
    // background-image: url('/v1/img/logo-2.png');
  }
  .nav-btn-box{
    width: 0;
    flex: 1;
    padding-left: 64px;
    .btn{
      font-size: 20px;
      line-height: 50px;
      padding: 0 15px;
      height: 100%;
      position: relative;
      color: #fff;
      font-weight: 300;
      &.on{
        color: #fff;
        font-weight: 400;
        &::before{
          content: "";
          width: calc(100% - 30px);
          height: 4px;
          border-radius: 2px;
          position: absolute;
          bottom: 0;
          left: 15px;
          background-color: #fff;
          animation:  navBtnShow .4s forwards;
        }
      }
    }
  }
  .btn-box{
    .btn{
      width: 100px;
      height: 30px;
      border-radius: 20px;
      background-color: #fff;
      color: #469AFF;
      font-size: 14px;
      &:last-child{
        margin-left: 20px;
      }
      .icon{
        width: 22px;
        height: 22px;
        margin-right: 10px;
        // background-image: url('/v1/img/icon-2.png');
      }
    }
    .qrcode{
      width: 122px;
      height: 130px;
      position: absolute;
      left: -11px;
      top: 30px;
      display: none;
    }
    .hover{
      position: relative;
      cursor: pointer;
    }
    .hover:hover{
      .qrcode{
        display: block;
      }
    }
  }
}

@keyframes headerShow {
  from {
    top:-90px;
  }
  to {
    top:0
  }
}
@keyframes navBtnShow {
  from {
    opacity: 0;
    transform: scaleX(0);
    transform-origin:center
  }
  to {
    opacity: 1;
    transform: scaleX(100%);
    transform-origin:center
  }
}
</style>
